<?php
/**
 * @package mikrokosmos
 * mk simple svg support file created on 31-mar-2005
 * jaco_at_pixeldump_dot_org
 * very, very, very draft
 */

/**
 * simple svg reader
 */
class MKSimpleSvgReader{

 	var $svgFileName;
 	var $svgDir = SERVER_MKSVG;
 	var $itemID = 1;
 	var $svg;
 	var $svgHeight = 0;
 	var $svgWidth = 0;
 	var $sc;

 	var $cmds = array();

 	var $gradientColors = array();
 	var $fillStatus = false;
 	var $strokeStatus = false;

 	var $debugShape;

 	// the constructor
 	function MKSimpleSvgReader($svgFileName = "", $svgDir = SERVER_MKSVG, $shapeID = 1){

		//$this->debugShape = new MKShapeContainer("", 10, $shapeID);
		//$this->debugShape->add_fillStyle_solid("#FF0000");

 		if(strlen($svgDir)) $this->svgDir = $svgDir;
 		$this->svgFileName = $svgFileName;
 		$this->itemID = $shapeID;

 		if(strlen($svgFileName)){ $this->read_SVG(); }
 	}

	//
	function set_svgFileName($svgFileName) {$this->svgFileName = $svgFileName; }
	function get_svgFileName() {return $this->svgFileName; }

	//
	function set_svgDir($svgDir) {$this->svgDir = $svgDir; }
	function get_svgDir() {return $this->svgDir; }

	//
	function set_svgHeight($svgHeight) {$this->svgHeight = $svgHeight; }
	function get_svgHeight() {return $this->svgHeight; }

	//
	function set_svgWidth($svgWidth) {$this->svgWidth = $svgWidth; }
	function get_svgWidth() {return $this->svgWidth; }

	//
	function set_itemID($itemID){
		$this->itemID = $itemID;
		if(isset($this->sc)) $this->sc->set_itemID($this->itemID);
	}
	function get_itemID() {return $this->itemID; }

	// alias of set[get]_itemID
	function set_shapeID($shapeID = 1){
		$this->set_itemID($shapeID);
	}
	function get_shapeID() { return $this->itemID; }

	// svg
	// sc
	// setter/getter does not concern the user

	// reads svg from file, use xmllib
 	function read_SVG(){

		$this->sc = new MKShapeContainer();
		$this->sc->set_itemID($this->itemID);
		$this->sc->set_tagID(SHAPE_ID3);
		$this->svg = new XmlLib_xmlParser($this->svgDir .$this->svgFileName);
		$sd = 0;

 		$doc = & $this->svg->getDocument();
		$cl = $doc->childNodes();

		foreach($cl as $n){

			if($n->nodeName == "svg"){

				$this->svgHeight = floor($n->getAttribute("height"));
				$this->svgWidth = floor($n->getAttribute("width"));

				$cl1 = $n->childNodes();

				foreach($cl1 as $n1){

					if($n1->nodeName == "defs"){ // gradients fill definition
						$defs = $n1->childNodes();

						foreach($defs as $d){
							$id = $d->getAttribute("id");

							// note that strtolower is a workaround to buggy xmllib nodeName parsing
							if(strpos(strtolower($d->nodeName), "gradient") !== false) {
								$this->parse_gradient($d);
							}
						}
					}
					else if($n1->nodeName == "path"){
						$this->parse_pathNode($n1, $sd);
						$sd++;
					}
					else if($n1->nodeName == "rect"){
						$this->parse_rectNode($n1, $sd);
						$sd++;
					}
					else if($n1->nodeName == "g"){ // path group
						$cl2 = $n1->childNodes();

						foreach($cl2 as $n2){

							if($n2->nodeName == "path"){
								$this->parse_pathNode($n2, $sd);
								$sd++;
							}
							else if($n2->nodeName == "rect"){
								$this->parse_rectNode($n2, $sd);
								$sd++;
							}
						}
					}
				}
			}
		}
 	}


 	function parse_gradient($gdNode){

		$lgAr = array();
		$lgAr["id"] = $gdNode->getAttribute("id");

		$nodeName = strtolower($gdNode->nodeName);
		$gmStr = $gdNode->getAttribute("gradientTransform");
		$tranform = "";

		if($gmStr != NULL){
			$transform = $this->parse_transform($gmStr);
		}

		if(strtolower($nodeName) == "lineargradient"){

			$lgAr["type"] = LINEAR_GRADIENT_FILL;
			$x1 = (float) $gdNode->getAttribute("x1");
			$x2 = (float) $gdNode->getAttribute("x2");
			$y1 = (float) $gdNode->getAttribute("y1");
			$y2 = (float) $gdNode->getAttribute("y2");

			if($x1 != NULL){
				// for debugging scope
				//$this->sc->clear_fillStyle();
				//$this->sc->add_lineStyle(0.5, "#000000");
				//$this->sc->add_line($x1, $y1, $x2, $y2);

				$p1 = array();
				$p2 = array();

				if(isset($transform["factors"])){

					$mType = $transform["type"];
					if($mType == "matrix"){
						$p1 = apply_matrix($x1, $y1, $transform["factors"]);
						$p2 = apply_matrix($x2, $y2, $transform["factors"]);
					}
					else if($mType == "translate"){

						$p1["x"] = $x1 + $transform["factors"]["tx"];
						$p1["y"] = $y1 + $transform["factors"]["ty"];
						$p2["x"] = $x2 + $transform["factors"]["tx"];
						$p2["y"] = $y2 + $transform["factors"]["ty"];
					}
					else if($mType == "scale"){

						$f = array();
						$f["a"] = $transform["factors"]["sx"];
						$f["b"] = 0;
						$f["c"] = 0;
						$f["d"] = $transform["factors"]["sy"];
						$f["e"] = 0;
						$f["f"] = 0;

						$p1 = apply_matrix($x1, $y1, $f);
						$p2 = apply_matrix($x2, $y2, $f);
					}

					$x1 = $p1["x"];
					$y1 = $p1["y"];
					$x2 = $p2["x"];
					$y2 = $p2["y"];
				}

				$lgAr["x1"] = $x1;
				$lgAr["x2"] = $x2;
				$lgAr["y1"] = $y1;
				$lgAr["y2"] = $y2;
			}
		}
		else if(strtolower($nodeName) == "radialgradient"){

			$lgAr["type"] = RADIAL_GRADIENT_FILL;

			$cx = (float) $gdNode->getAttribute("cx");
			$cy = (float) $gdNode->getAttribute("cy");
			$fx = (float) $gdNode->getAttribute("fx");
			$fy = (float) $gdNode->getAttribute("fy");
			$r =  (float) $gdNode->getAttribute("r");
			$d = $r * 2;
			$width = $d;
			$height = $d;

			if($cx != NULL){

				if(isset($transform["factors"])){

					$f = array();
					$mType = $transform["type"];

					if($mType == "matrix"){
						$f = $transform["factors"];
					}
					else if($mType == "translate"){
						$f["a"] = 1;
						$f["b"] = 0;
						$f["c"] = 0;
						$f["d"] = 1;
						$f["e"] = $transform["factors"]["tx"];
						$f["f"] = $transform["factors"]["ty"];
					}
					else if($mType == "scale"){

						$f["a"] = $transform["factors"]["sx"];
						$f["b"] = 0;
						$f["c"] = 0;
						$f["d"] = $transform["factors"]["sy"];
						$f["e"] = 0;
						$f["f"] = 0;
					}


					$p1 = apply_matrix($cx, $cy, $f);
					$p2 = apply_matrix($fx, $fy, $f);
					$cx = $p1["x"];
					$cy = $p1["y"];
					$fx = $p1["x"];
					$fy = $p1["y"];

					$coords = array();
					$coords[0] = apply_matrix(0, 0, $f);
					$coords[1] = apply_matrix($d, 0, $f);
					$coords[2] = apply_matrix($d, $d, $f);
					$coords[3] = apply_matrix(0, $d, $f);
					$coords[4] = $coords[0];

					$c1 = $coords[0]["x"] - $coords[1]["x"];
					$c2 = $coords[0]["y"] - $coords[1]["y"];
					$ipoHeight = sqrt($c1 * $c1 + $c2 * $c2);
					$lc = max($c1, $c2);

					$c1 = $coords[0]["x"] - $coords[3]["x"];
					$c2 = $coords[3]["y"] - $coords[0]["y"];
					$ipoWidth = sqrt($c1 * $c1 + $c2 * $c2);

					$radAngle = acos($lc / $ipoHeight);
					$lgAr["rotation"] = rad2deg($radAngle);
					$height = $ipoHeight;
					$width = $ipoWidth;
				}

				$lgAr["cx"] = $cx;
				$lgAr["cy"] = $cy;
				$lgAr["fx"] = $fx;
				$lgAr["fy"] = $fy;
				$lgAr["r"] = $r;
				$lgAr["width"] = $width;
				$lgAr["height"] = $height;
			}
		}

		$refID = $gdNode->getAttribute("xlink:href");
		if($refID != NULL) $lgAr["refID"] = substr($refID, 1); // strip "#" char

		$cn = $gdNode->childNodes();

		if(count($cn)){

			$colors = array();

			foreach($cn as $c){

				$cName = $c->nodeName();
				$cidx = count($colors);

				if($cName == "stop"){

					$sStr = $c->getAttribute("style");
					$styles = preg_split("/;/", $sStr);
					$sid = $c->getAttribute("id");

					foreach($styles as $s){

						$siAr = preg_split("/:/", $s);

						if($siAr[0] == "stop-color"){
							$colors[$cidx] = parse_color($siAr[1]);
						}
						if($siAr[0] == "stop-opacity"){
							$alpha = $siAr[1];

							if($alpha == NULL) $alpha = 1;
							$colors[$cidx]["alpha"] = round($alpha * 0xff);
						}
					}
				}
			}

			$lgAr["colors"] = $colors;
		}

		$this->gradientColors[] = $lgAr;
 	}

 	function get_gradientById($gid){

 		foreach($this->gradientColors as $gradient){
 			$id = $gradient["id"];
 			if($id == $gid) return $gradient;
 		}
		return false;
 	}

	//
 	function rebuild_gradient($initialGID){

		$gradient = array();
		$nextID = $initialGID;
		$gCount = count($this->gradientColors);

		for($i = 0; $i < $gCount; $i++){

			$g = $this->get_gradientById($nextID);

			if($initialGID == $nextID)
				$gType = $g["type"];

			if(!$g){
				break;
			}

			foreach($g as $k => $v){
				if($k != "id")	$gradient[$k] = $v;
			}

			if(!isset($g["refID"])) break;

			$nextID = $g["refID"];
 		}
 		$gradient["type"] = $gType;

 		return $gradient;
 	}


 	//
 	function parse_transform($tStr){

 		if($tStr == NULL){
 			return "";
 		}
 		$transform = array();
		$factors = array();

 		$dataStr = substr($tStr, strpos($tStr, "(") + 1);
 		$dataStr = substr($dataStr, 0, -1);

 		if(strpos($tStr, "matrix") !== false){
 			$transform["type"] = "matrix";
 			$rawMatrix = preg_split("/\,/", $dataStr);
	 		$factors["a"] = (float) $rawMatrix[0];
	 		$factors["b"] = (float) $rawMatrix[1];
	 		$factors["c"] = (float) $rawMatrix[2];
	 		$factors["d"] = (float) $rawMatrix[3];
	 		$factors["e"] = (float) $rawMatrix[4];
	 		$factors["f"] = (float) $rawMatrix[5];
 		}
 		else if(strpos($tStr, "translate") !== false){

 			$transform["type"] = "translate";

 			$factors["tx"] = 0;
 			$factors["ty"] = 0;
 			if(strpos($tStr, ",") != false){
 				$translate = preg_split("/\,/", $dataStr);
 				$factors["tx"] = (float) $translate[0];
 				$factors["ty"] = (float) $translate[1];
 			}
 			else $factors["tx"] = (float) $dataStr;
 		}
 		else if(strpos($tStr, "rotate") !== false){
 			$transform["type"] = "rotate";
 		}
 		else if(strpos($tStr, "scale") !== false){
 			$transform["type"] = "scale";
 			$factors["sx"] = 1;
 			$factors["sy"] = 1;
 			if(strpos($tStr, ",") != false){
				$scale = preg_split("/\,/", $dataStr);
				$factors["sx"] = (float) $scale[0];
				$factors["sy"] = (float) $scale[1];
 			}
 			else {
				$factors["sx"] = (float) $tStr;
				$factors["sy"] = $factors["sx"];
 			}
 		}
 		else if(strpos($tStr, "skewX") !== false){
 			$transform["type"] = "skewX";
 		}
 		else if(strpos($tStr, "skewY") !== false){
 			$transform["type"] = "skewY";
 		}

 		$transform["factors"] = $factors;

 		return $transform;
 	}


 	//
 	function parse_rectNode($rectNode, $sd){

 		$rectID = $rectNode->getAttribute("id");

		$rectAr = array();
		$style = $rectNode->getAttribute("style");
		$transformStr = $rectNode->getAttribute("transform");
		$transform = $this->parse_transform($transformStr);

		$styleInfo = get_styleInfo($style, $transform);

		$this->fillStatus = isset($styleInfo["fillColor"]);
		$this->strokeStatus = isset($styleInfo["strokeColor"]);

		if($sd && $this->fillStatus){
			$this->sc->increase_shapeDepth(true);
		}

		$this->set_shape_style($styleInfo);

		$rectAr["x"] = (float) $rectNode->getAttribute("x");
		$rectAr["y"] = (float) $rectNode->getAttribute("y");
		$rectAr["width"] = (float) $rectNode->getAttribute("width");
		$rectAr["height"] = (float) $rectNode->getAttribute("height");

		if(isset($transform["type"])){

			$coords = array();
			$x1 = $rectAr["x"];
			$y1 = $rectAr["y"];
			$x2 = $x1 + $rectAr["width"];
			$y2 = $y1;
			$x3 = $x2;
			$y3 = $y2 + $rectAr["height"];
			$x4 = $x1;
			$y4 = $y3;

			$type = $transform["type"];

			if($type == "matrix"){

				$coords[0] = apply_matrix($x1, $y1, $transform["factors"]);
				$coords[1] = apply_matrix($x2, $y2, $transform["factors"]);
				$coords[2] = apply_matrix($x3, $y3, $transform["factors"]);
				$coords[3] = apply_matrix($x4, $y4, $transform["factors"]);
			}

			$coords[4] = $coords[0];
			$this->sc->add_mixed_poly($coords);
		}
		else  $this->sc->add_rect($rectAr["x"], $rectAr["y"], $rectAr["width"], $rectAr["height"]);
 	}

 	//
 	function parse_pathNode($pathNode, $sd = 0){

		$drawingStr = $pathNode->getAttribute("d");

		$style = $pathNode->getAttribute("style");
		if(!isset($style)) $style = "fill:black;fill-opacity:1";
		$pathID = $pathNode->getAttribute("id");

		$transformStr = $pathNode->getAttribute("transform");
		$transform = $this->parse_transform($transformStr);

		$styleInfo = get_styleInfo($style, $transform);

		$this->fillStatus = isset($styleInfo["fillColor"]);
		$this->strokeStatus = isset($styleInfo["strokeColor"]);

		if($sd && $this->fillStatus){
			$this->sc->increase_shapeDepth(true);
		}

		$this->set_shape_style($styleInfo);
		$sodipodiType = $pathNode->getAttribute("sodipodi:type");

		if($sodipodiType != NULL){
			if($sodipodiType == "arc")
				$this->parse_arcNode($pathNode, true);
		}
		else {

			if($this->fillStatus){
				$this->parse_path($drawingStr, $transform);
			}
			else $this->parse_sketch($drawingStr, $transform);
 		}
 	}


	//
 	function set_shape_style($styleInfo){

 		$this->sc->clear_fillStyle();
 		$this->sc->clear_lineStyle();

 		if($this->fillStatus){

			$fillColor = $styleInfo["fillColor"];

 			if(isset($fillColor["refID"])){

				$refID = $fillColor["refID"];
				$gradientRef = $this->get_gradientById(($refID));

				if(is_array($gradientRef)){

					$gradient = $this->rebuild_gradient($refID);

					$mad = array();
					$gType = $gradient["type"];
					$colors = $gradient["colors"];
					$cCount = count($colors);

					$step = 0xff / ($cCount - 1);
					$ratios = array();

					for($j = 0; $j < $cCount; $j++)	$ratios[] = round($j * $step);

					if($gType == LINEAR_GRADIENT_FILL){

						$x1 = $gradient["x1"];
						$x2 = $gradient["x2"];
						$y1 = $gradient["y1"];
						$y2 = $gradient["y2"];

						$maxX = max($x1, $x2);
						$minX = min($x1, $x2);
						$maxY = max($y1, $y2);
						$minY = min($y1, $y2);

						$dx = $x2 - $x1;
						$dy = $y2 - $y1;
						$ipo = sqrt($dx * $dx + $dy * $dy);
						$angle = rad2deg(acos($dx / $ipo));
						$dx = abs($dx);
						$dy = abs($dy);

						$mad["x"] = $minX + ($maxX - $minX) / 2;
						$mad["y"] = $minY + ($maxY - $minY) / 2;
						$mad["width"] = $ipo;
						$mad["height"] = 10;

						//$this->debugShape->add_rect($mad["x"] - 5, $mad["y"] - 5, 10, 10);

						$mad["rotation"] = round($angle, 2);
						if($y1 > $y2) $mad["rotation"] *= -1;

						$this->sc->add_gradient_fill(LINEAR_GRADIENT_FILL, $colors, $ratios, $mad, true);
					}
					else if($gType == RADIAL_GRADIENT_FILL){

						$mad["x"] = $gradient["fx"];
						$mad["y"] = $gradient["fy"];
						$mad["width"] = $gradient["width"];
						$mad["height"] = $gradient["height"];
						$mad["rotation"] = $gradient["rotation"];

						$this->sc->add_gradient_fill(RADIAL_GRADIENT_FILL, $colors, $ratios, $mad);
					}
				}
 			}
			else {
				$this->sc->add_fillStyle_solid($styleInfo["fillColor"]);
			}
		}
 		if($this->strokeStatus){
 			$this->sc->add_lineStyle($styleInfo["strokeWidth"], $styleInfo["strokeColor"]);
 		}
 	}

 	//
 	function parse_sketch($cStr, $transform = array()){

		$drawingCommands = get_drawing_coords($cStr);

		foreach($drawingCommands["coordGroup"] as $coords){
			$this->sc->add_sketch($coords);
		}
 	}


	// new experimental parse path
	// this method has to be called only if there is at least one "z" command
 	function parse_path($cStr, $transform = array()){

 		if($this->fillStatus) $this->sc->select_fill(RIGHT_FILL);

 		$oldFill = RIGHT_FILL;
		$shapeDC = array();

		$shapeDC[] = get_drawing_coords($cStr);
		$sdcCount = count($shapeDC);

		if(isset($transform["type"])){ // coordGroup need to be tranformed
			$tType = $transform["type"];
			$factors = $transform["factors"];

			if($tType == "translate"){
				/* TODO: translate points */
			}
			else if($tType == "matrix"){
				for($i = 0; $i < $sdcCount; $i++){

					$cCount = count($shapeDC[$i]["coordGroup"]);

					for($j = 0; $j < $cCount; $j++){

						$coords = $shapeDC[$i]["coordGroup"][$j];
						$ccCount = count($coords);
						$c = $shapeDC[$i]["coordGroup"][$j];

						if($ccCount == 2){
							$p = apply_matrix($c["x"], $c["y"], $factors);
							$shapeDC[$i]["coordGroup"][$j] = $p;
						}
						else if($ccCount == 4){
							$p1 = apply_matrix($c["cx"], $c["cy"], $factors);
							$p2 = apply_matrix($c["ax"], $c["ay"], $factors);
							$shapeDC[$i]["coordGroup"][$j]["cx"] = $p1["x"];
							$shapeDC[$i]["coordGroup"][$j]["cy"] = $p1["y"];
							$shapeDC[$i]["coordGroup"][$j]["ax"] = $p2["x"];
							$shapeDC[$i]["coordGroup"][$j]["ay"] = $p2["y"];
						}
						else if($ccCount == 6){
							$p1 = apply_matrix($c["c1x"], $c["c1y"], $factors);
							$p2 = apply_matrix($c["c2x"], $c["c2y"], $factors);
							$p3 = apply_matrix($c["ax"], $c["ay"], $factors);
							$shapeDC[$i]["coordGroup"][$j]["c1x"] = $p1["x"];
							$shapeDC[$i]["coordGroup"][$j]["c1y"] = $p1["y"];
							$shapeDC[$i]["coordGroup"][$j]["c2x"] = $p2["x"];
							$shapeDC[$i]["coordGroup"][$j]["c2y"] = $p2["y"];
							$shapeDC[$i]["coordGroup"][$j]["ax"] = $p3["x"];
							$shapeDC[$i]["coordGroup"][$j]["ay"] = $p3["y"];
						}
					}
				}
			}
		}

		$coordGroup = $shapeDC[0]["coordGroup"];

		foreach($coordGroup as $coords){
			$masterBoundary = find_boundary($coords);
			$ds = find_drawing_direction($masterBoundary, false);

			if($ds < 0){
				$this->sc->select_fill(LEFT_FILL);
	 			$oldFill = LEFT_FILL;
			}

			if(count($coords) > 2){
				$this->sc->add_mixed_poly($coords);
			}
		}


		if($sdcCount > 1){ // more shapes, we need to check if there is holes

			for($i = 1; $i < $sdcCount; $i++){

				$coordGroup = $shapeDC[$i]["coordGroup"];

				foreach($coordGroup as $coords){
					$boundary = find_boundary($coords);
					$ds = find_drawing_direction($boundary, false);

					$fill = RIGHT_FILL;

					if(is_in_boundary($masterBoundary, $boundary) || $ds < 0)
						$fill = LEFT_FILL;

					$this->sc->select_fill($fill);
					$this->sc->add_mixed_poly($coords);
				}
			}
		}
 	}

	function parse_arcNode($arcNode, $sodipodiOrigin = true){

		$pfx = "";
		if($sodipodiOrigin) $pfx = "sodipodi:";

		$cx = (float) $arcNode->getAttribute($pfx ."cx");
		$cy = (float) $arcNode->getAttribute($pfx ."cy");
		$rx = (float) $arcNode->getAttribute($pfx ."rx");
		$ry = (float) $arcNode->getAttribute($pfx ."ry");

		$transformStr = $arcNode->getAttribute("transform");
		$transform = $this->parse_transform($transformStr);

		if(isset($transform["type"])){
			$type = $transform["type"];

			if($type == "translate"){
				$cx += $transform["factors"]["tx"];
				$cy += $transform["factors"]["ty"];
			}
			else if($type == "matrix"){

				// take care, this transformation is almost pointless
				/* TODO must be revised	*/
				$p = apply_matrix($cx, $cy, $transform["factors"]);
				$cx = $p["x"];
				$cy = $p["y"];
			}
		}

		$this->sc->add_ellipse($cx, $cy, $rx * 2, $ry * 2, "center");
	}

	//
	function set_shapeDepth($shapeDepth){ $this->sc->set_shapeDepth($shapeDepth);}
	function get_shapeDepth(){ return $this->sc->get_shapeDepth();}

	//
	function set_depth($depth){ $this->sc->set_depth($depth); }

	//
	function get_placeDepth(){ return $this->sc->get_placeDepth(); }

	//
	function get_placeObject2() { return $this->sc->get_placeObject2(); }

	//
	function set_replace_flag($rFlag = true) { $this->sc->set_replace_flag($rFlag = true);}


	// set translation data for placeObject2
	function move($x, $y, $depthFlag = false, $isChange = false){
		$this->sc->move($x, $y, $depthFlag, $isChange);
	}

	// set scale data for placeObject2
	function scale($scaleX, $scaleY, $depthFlag = false, $isChange = false){
		$this->sc->scale($scaleX, $scaleY, $depthFlag, $isChange);
	}

	// set rotation data for placeObject2
	function rotate($rotation, $depthFlag = false, $isChange = false){
		$this->sc->rotate($rotation, $depthFlag, $isChange);
	}

	// mask other graphic objects
	function set_mask($maskDepth = 1){ $this->sc->set_mask($maskDepth); }

	// returns defineshape data
 	function get_buf(){ return $this->sc->update_tagData(); }

	// returns defineshape data (alias of get_buf)
 	function update_tagData(){
 		$this->sc->set_itemID($this->itemID);
 		return $this->sc->update_tagData();
 	}

	// returns defineshape placing data
 	function update_place_tagData($replacingDepth = -1){
 		return $this->sc->update_place_tagData($replacingDepth);
 	}
}

/**
 * write svg from given shape container data
 * this is far from being implemented, just a placeholder...
 */
class MKSvgWriter{

	var $scTagData;				// shape container tagData
	var $poTagData;				// placeBuf

	var $sc;					// shape container
	var $svgDir = SERVER_MKSVG;	// destination path to svg creation

	// the constructor
	function MKSvgWriter($scTagData = "", $poTagData = "", $sc = -1){
		$this->scTagData = $scTagData;
		$this->poTagData = $poTagData;

		if(is_nan($sc)){
			if(strlen($scTagData))
				$this->sc = new MKShapeContainer($scTagData);

			if(strlen($poTagData)){
				$po = new MKPlaceObject2($poTagData);
				$this->sc->set_placeObject2($po);
			}
		}
		else $this->sc = $sc;
	}

	function set_svgDir($svgDir) { $this->svgDir = $svgDir; }
	function get_svgDir() { return $this->svgDir; }

	/* TODO: implement writing methods */
}

// ---------------- end of MKcs_svg --------------
?>
